package com.base.study.presenter;

import android.app.Activity;

import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.bean.UpdateScopeStatEntity;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.http.utils.CallBackImpl;
import com.base.commonlib.utils.RxBus2;
import com.base.study.bean.CurriculumCatalogBean;
import com.base.study.bean.CurriculumIntroduceBean;
import com.base.study.view.CurriculumDetailView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.disposables.Disposable;

/**
 * Created by Administrator on 2020/2/26.
 */

public class CurriculumDetailPresenter extends BasePresenter<CurriculumDetailView> {
    public CurriculumDetailPresenter(CurriculumDetailView view, Activity activity) {
        super(view, activity);
    }

    /**
     * 积分
     */
    public void getJifeng(String courseRootId,String tenantId) {
        Map<String, Object> map = new HashMap<>();
//        if ("95cf0f4698474b37a1c20af89b0b4217".equals(tenantId)){
//            map.put("settingKey","08020013");
//        }else {
//            map.put("settingKey","08020004");
//        }

        map.put("settingKey","08020013");
        map.put("funcMainId", "edu");
        map.put("courseRootId", courseRootId);
        Disposable enqueue = RealNetWorkUtil.postContent().method("api-function/integral/save").content(map)
                .build().enqueue(String.class, new CallBackImpl<String>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                    }

                    @Override
                    public void onNext(String str) {
                        if (!str.contains("上限")){
                            mView.showMes(str);
                            RxBus2.getInstance().post(new UpdateScopeStatEntity(1));
                        }
                    }
                });

        mCompositeDisposable.add(enqueue);
    }

    /**
     * 介绍
     *
     * @param id
     */
    public void getInfo(String id) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        Disposable enqueue = RealNetWorkUtil.get().method("api-train/course/info").params(map)
                .build().enqueue(CurriculumIntroduceBean.class, new CallBackImpl<CurriculumIntroduceBean>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.showError();
                        mView.returnCatalogError();
                    }

                    @Override
                    public void onNext(CurriculumIntroduceBean bean) {
                        mView.returnIntroduce(bean);
                    }
                });
        mCompositeDisposable.add(enqueue);
    }

    /**
     * 目录
     *
     * @param id
     */
    public void getCatelogListData(String id) {
        Map<String, Object> map = new HashMap<>();
        map.put("courseId", id);
        Disposable enqueue = RealNetWorkUtil.get().method("api-train/chapter/list").params(map)
                .build().enqueueForArray(CurriculumCatalogBean.class, new CallBackImpl<List<CurriculumCatalogBean>>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.showError();
                        mView.returnCatalogError();
                    }

                    @Override
                    public void onNext(List<CurriculumCatalogBean> list) {
                        mView.returnCatalogList(list);
                    }
                });
        mCompositeDisposable.add(enqueue);
    }

}
